import { currentUserID } from "@/utils/common.js";
import { utils } from 'hi-ui';
//采购退货数据集配置
export default {
    id: "ReturnDetailEntity",
    returnTotal: true,
    modelFile: "purchase/return/dataset/ReturnDetailEntity.xml",
    //主从配置
    relation: {
        selfField: ["FNUMBER"],
        parentField: ["FNUMBER"]
    },
    sortFields: [
        "FID",
        "FNUMBER",
        "FINSPECTNUMBER",
        "FGOODSNUMBER",
        "FBARCODE",
        "FDESC",
        "FUNIT",
        "FTHAMOUNT",
        "FAMOUNT",
        "FPRICE",
        "FMONEY",
        "FBRAND",
        "FRATE",
        "FRATEMONEY",
        "FNOTE",
        "FUSERID",
        "FCREATEDATE",
        "FENTERPRISEDESC",
        "FENTERPRISEID",
        "FSHOPDESC",
        "FSHOPDESCID",
        "FSORT"
    ],
    element: {
        eleSort: {
            field: "FSORT",
        }
    },
    fields: {
        FID: {
            name: "FID", //字段ID
            label: "ID", //字段描述
            dbtype: "dbString", //数据类型
            default: {
                //默认值
                //rule: 'first', //prior   填充规则
                exps: (data) => {
                    //填充表达式
                    return utils.string.guid();
                },
            },
        },

        FNUMBER: {
            name: "FNUMBER", //字段ID
            label: "单号", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            readonly: true,
            length: 25,
        },
        FINSPECTNUMBER: {
            name: "FINSPECTNUMBER", //字段ID
            label: "验收入库单", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            readonly: true,
            length: 25,
        },
        FSORT: {
            name: "FSORT", //字段ID
            label: "排序", //字段描述
            dbtype: "dbInt", //数据类型

        },
        FUSERID: {
            name: "FUSERID", //字段ID
            label: "创建人", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            readonly: true,
            length: 25,
            default: {
                //默认值
                exps: (data) => {
                    //填充表达式
                    return currentUserID();
                },
            },
        },

        FCREATEDATE: {
            name: "FCREATEDATE", //字段ID
            label: "创建时间", //字段描述
            dbtype: "dbDate", //数据类型
            required: true,
            readonly: true,
            default: {
                //默认值
                exps: (data) => {
                    //填充表达式
                    return utils.date.format(new Date(), "yyyy-MM-dd HH:mm:ss");
                },
            },
        },
        FGOODSNUMBER: {
            name: "FGOODSNUMBER", //字段ID
            label: "店内编码", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            readonly: true,
            length: 25,
        },
        FBARCODE: {
            name: "FBARCODE", //字段ID
            label: "条形码", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            readonly: true,
            length: 25,
        },
        FDESC: {
            name: "FDESC", //字段ID
            label: "通用名称", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            readonly: true,
            length: 25,
        },

        FSPEC: {
            name: "FSPEC", //字段ID
            label: "规格", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            readonly: true,
            length: 100,
        },

        FBRAND: {
            name: "FBRAND", //字段ID
            label: "品牌", //字段描述
            dbtype: "dbString", //数据类型
            readonly: true,

            length: 25,
        },
        FUNIT: {
            name: "FUNIT", //字段ID
            label: "单位", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            readonly: true,
            length: 25,
        },
        FTHAMOUNT: {
            name: "FTHAMOUNT", //字段ID
            label: "可退货数量", //字段描述
            dbtype: "dbFloat", //数据类型
            required: true,
            readonly: true,
        },
        FAMOUNT: {
            name: "FAMOUNT", //字段ID
            label: "退货数量", //字段描述
            dbtype: "dbFloat", //数据类型
            required: true,
            fireTarget: ["FMONEY"]
        },
        FPRICE: {
            name: "FPRICE", //字段ID
            label: "采购单价", //字段描述
            dbtype: "dbFloat", //数据类型
            required: true,

            fireTarget: ["FMONEY"]
        },
        FMONEY: {
            name: "FMONEY", //字段ID
            label: "金额", //字段描述
            dbtype: "dbFloat", //数据类型
            required: true,
            readonly: true,
            default: {
                //默认值
                exps: (data) => {
                    if (data.FPRICE && data.FAMOUNT)
                        return utils.number.accMul(data.FPRICE, data.FAMOUNT)
                },
            },
        },
        FRATE: {
            name: "FRATE", //字段ID
            label: "税率", //字段描述
            dbtype: "dbFloat", //数据类型
        },
        FRATEMONEY: {
            name: "FRATEMONEY", //字段ID
            label: "税额", //字段描述
            dbtype: "dbFloat", //数据类型
        },
        FENTERPRISEDESC: {
            name: "FENTERPRISEDESC", //字段ID
            label: "企业名称", //字段描述
            dbtype: "dbString", //数据类型
            length: 25,
        },
        FENTERPRISEID: {
            name: "FENTERPRISEID", //字段ID
            label: "企业ID", //字段描述
            dbtype: "dbString", //数据类型
            length: 25,
        },
        FSHOPDESC: {
            name: "FSHOPDESC", //字段ID
            label: "店铺", //字段描述
            dbtype: "dbString", //数据类型
            length: 25,
            required: true,
        },
        FSHOPDESCID: {
            name: "FSHOPDESCID", //字段ID
            label: "店铺编号", //字段描述
            dbtype: "dbString", //数据类型
            length: 25,
            required: true,
        },
        FNOTE: {
            name: "FNOTE", //字段ID
            label: "备注", //字段描述
            dbtype: "dbString", //数据类型
            length: 250,
        },
    },
    validateList: [{
        "expr": function (store) {
            var data = store.data;
            for (var i = 0; i < data.length; i++) {
                var item = data[i];
                var FTHAMOUNT = item.FTHAMOUNT, FAMOUNT = item.FAMOUNT || 0;
                if (FAMOUNT > FTHAMOUNT) {
                    let error = new Error(item.FDESC + "退货数量不能大于可退货数量");
                    return error
                }


            }

        }
    }]
}